package com.project.config;

import dev.langchain4j.data.document.Document;
import dev.langchain4j.data.document.DocumentSplitter;
import dev.langchain4j.data.segment.TextSegment;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Slf4j
public class FundDocumentSplitter implements DocumentSplitter {
    @Override
    public List<TextSegment> split(Document document) {
        List<TextSegment> segments = new ArrayList<>();
        String[] parts = document.text().split("\n");
        for (String part : parts) {
            try {
                TextSegment textSegment = TextSegment.from(part);
                segments.add(textSegment);
            } catch (Exception e) {
                log.error("数据分割异常part:{}, msg:{}",part, e.getMessage());
            }
        }
        return segments;
    }


}
